package com.yj.apiback.controller;

import com.yj.apiback.result.Result;
import com.yj.apiback.util.SessionUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.constraints.Min;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/cart")
public class CartController {

    //session详情
    @GetMapping("/list")
    @ResponseBody
    public Result list() {
        Map<String, String> data = new HashMap<String, String>();
        data.put("msg", "this is cart list page");
        return Result.success(data);
    }

    @GetMapping("/add")
    @ResponseBody
    public Result add(@Min(value = 1,message = "商品id需要>0")@RequestParam("goodsId") Long goodsId) {
        System.out.println("商品id:"+goodsId);
        Map<String, String> data = new HashMap<String, String>();
        //得到当前用户的id
        data.put("userId", String.valueOf(SessionUtil.getCurrentUser().getUserid()));
        data.put("goodsId", String.valueOf(goodsId));
       //msg
        data.put("msg", "加入购物车成功");
        return Result.success(data);
    }
}
